const { Model, DataTypes } = require('sequelize');

const sequelize = require('./database');
const TeamGroup = require('./teamgroup');
const User = require('./user');
const MatchesGroup = require('./matchgroup');
const Team = require('./projectteam');
const Match = require('./match');


class Staff extends Model {}

Staff.init({
  role: {
    type: DataTypes.STRING,
    allowNull: true,
    comment:"人员身份"
  },
  idcard: {
    type: DataTypes.STRING,
    allowNull: false,
    comment:"省份证号码",
    unique:false
  },
  urealName: {
    type: DataTypes.STRING,
    allowNull: false,
    comment:"姓名"
  },
  sex: {
    type: DataTypes.STRING,
    allowNull: false,
    comment:"性别"
  },
  birthday: {
    type: DataTypes.STRING,
    allowNull: false,
    comment:"出生日期"
  },
  
  phone: {
    type: DataTypes.STRING,
    allowNull: true,
    comment:"电话"
  },
  email: {
    type: DataTypes.STRING,
    allowNull: true,
    comment:"邮箱"
  },
  image: {
    type: DataTypes.STRING,
    allowNull: true,
    comment:"队伍图片"
  },
  teamGroupId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: TeamGroup, // 指定关联的模型
      key: 'id'
    }
  },
  matchId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: Match, // 指定关联的模型
      key: 'id'
    }
  },
  userId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: User, // 指定关联的模型
      key: 'id'
    }
  },
  matchesGroupId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment:"组别编号",
    references: {
      model: MatchesGroup, // 指定关联的模型
      key: 'id'
    }
  }
}, {
  sequelize,
  modelName: 'staff'
});
Staff.belongsTo(Match,{ foreignKey: 'matchId' })
Staff.belongsTo(TeamGroup,{ foreignKey: 'teamGroupId' })
Staff.belongsTo(User,{ foreignKey: 'userId' })
Staff.belongsTo(MatchesGroup,{ foreignKey: 'matchesGroupId' })
module.exports = Staff;